package cn.com.elite;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class EliteAction extends NonSessionAction{
	private static final Log log=LogFactory.getLog(EliteAction.class);
	private cn.com.elite.EliteBean ebean;
	private String sql;
	private int page_per=6;
	
	public String getSql() {
		return sql;
	}
	public void setSql(String sql) {
		this.sql = sql;
	}
	public cn.com.elite.EliteBean getEbean() {
		return ebean;
	}
	public void setEbean(cn.com.elite.EliteBean ebean) {
		this.ebean = ebean;
	}
	public ActionForward OpenWindow(ActionMapping mapping,
	 		ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) throws Exception{
		String guid1=Util.filter(request.getParameter("guid"));
		System.out.println("sql:"+sql);
		log.info("guid:"+guid1);
//		String sql=" select t.caseid guid,to_char(t.createddate,'yyyy-mm-dd hh24:mi:ss') time1,t.customer_name name1,t.ani1 phone,t.linkphone||','||t.linkphone2 mobile, " +
//				"t.e_mail mail,t.address adress,f.cfrom from1,t.title title,t.question countent from tabcchuzhou t left join  c_from f on t.fromstate=f.id where t.relation_id='"+guid1+"'";
		String sql1=sql+"'"+guid1+"'";
		log.info("sql:"+sql1);
		List list=ebean.chaxunList(sql1);
		if(list!=null&&list.size()>0){
			Map map=(Map)list.get(0);
			String guid=Util.filter((String)map.get("guid"));
			String time=Util.filter((String)map.get("time1"));
			String name=Util.filter((String)map.get("name1"));
			String phone=Util.filter((String)map.get("phone"));
			String mobile=Util.filter((String)map.get("mobile"));
			String mail=Util.filter((String)map.get("mail"));
			String adress=Util.filter((String)map.get("adress"));
			String from=Util.filter((String)map.get("from1"));
			String title=Util.filter((String)map.get("title"));
			String countent=Util.filter((String)map.get("countent"));
			request.setAttribute("guid",guid);
			request.setAttribute("time",time);
			request.setAttribute("name",name);
			request.setAttribute("phone",phone);
			request.setAttribute("mobile",mobile);
			request.setAttribute("mail",mail);
			request.setAttribute("adress",adress);
			request.setAttribute("from",from);
			request.setAttribute("title",title);
			request.setAttribute("countent",countent);
		}
		return mapping.findForward("success");
	}


	public ActionForward OpenWindow1(ActionMapping mapping,
	 		ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) throws Exception{
		String guid1=Util.filter(request.getParameter("guid"));
		System.out.println("sql:"+sql);
		log.info("guid:"+guid1);
		String sql1="select t.caseid as caseid,to_char(w.createddate,'yyyy-mm-dd hh24:mi:ss') as createddate,t.customer_name as customer_name,t.ani1 as ani1,t.linkphone as linkphone,cg.genderdescription as genderdescription,t.address as address,cw.worktypename as worktypename,t.question as question,t.method as method from tabcchuzhou t left join workorder2 w on t.relation_id=w.workorder_guid left join c_gender cg on t.gender=cg.gender left join c_workordertype cw on cw.id=t.worktype where t.relation_id='"+guid1+"'";
		log.info("sql:"+sql1);
		List list=ebean.chaxunList(sql1);
		if(list!=null&&list.size()>0){
			Map map=(Map)list.get(0);
			String caseid=Util.filter((String)map.get("caseid"));
			String createddate=Util.filter((String)map.get("createddate"));
			String customer=Util.filter((String)map.get("customer_name"));
			String ani1=Util.filter((String)map.get("ani1"));
			String linkphone=Util.filter((String)map.get("linkphone"));
			String genderdescription=Util.filter((String)map.get("genderdescription"));
			String address=Util.filter((String)map.get("address"));
			String worktypename=Util.filter((String)map.get("worktypename"));
			String question=Util.filter((String)map.get("question"));
			String method=Util.filter((String)map.get("method"));
			request.setAttribute("caseid",caseid);
			request.setAttribute("createddate",createddate);
			request.setAttribute("customer",customer);
			request.setAttribute("ani1",ani1);
			request.setAttribute("linkphone",linkphone);
			request.setAttribute("genderdescription",genderdescription);
			request.setAttribute("address",address);
			request.setAttribute("worktypename",worktypename);
			request.setAttribute("question",question);
			request.setAttribute("method",method);
		}
		return mapping.findForward("success1");
	}
}
